from unittest.mock import patch

from django.db import connection
from django.db.models import Avg
from django.test import TestCase

from polls.models import Teacher, Subject


# Create your tests here.
# if __name__ == '__main__':
#     queryset = Teacher.objects.values('subject').annotate(good=Avg('good_count'), bad=Avg('bad_count'))
#     print(queryset)

class TeacherModelTests(TestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        with patch('builtins.print') as mock_print:
            # 创建测试数据
            # cls.subject = Subject.objects.create(
            #     no=2,
            #     name='数学',
            #     intro='数学学科',
            #     is_hot=1
            # )
            # cls.teacher = Teacher.objects.create(
            #     name='张三1',
            #     detail='这是一个优秀的老师。',
            #     good_count=10,
            #     bad_count=2,
            #     subject=Subject.objects.create(name='数学')
            # )
            # # 输出查询结果以确认
            # queryset = Teacher.objects.all()
            # print(queryset)
            print('go')
        # 检查是否调用了print
        mock_print.assert_called()

    def test_name(self):
        print('test_name')
        # queryset = Teacher.objects.values('subject').annotate(good=Avg('good_count'), bad=Avg('bad_count'))
        # print(queryset)

    # def test_database_connection(self):
    #     print(connection.settings_dict)
